<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.projectName" size="large" clearable placeholder="项目名称" style="width: 190px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-input v-model="query.projectCode" size="small" clearable placeholder="项目编号" style="width: 190px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-input v-model="query.projectDescribe" size="small" clearable placeholder="项目描述" style="width: 190px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-input v-model="query.orderNumber" size="small" clearable placeholder="排序" style="width: 190px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-input v-model="query.createBy" size="small" clearable placeholder="创建者" style="width: 190px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-input v-model="query.updateBy" size="small" clearable placeholder="更新者" style="width: 190px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-input v-model="query.remark" size="small" clearable placeholder="备注" style="width: 190px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu> 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="项目名称" prop="projectName">
            <el-input v-model="form.projectName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="项目编号" prop="projectCode">
            <el-input v-model="form.projectCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="项目描述" prop="projectDescribe">
            <el-input v-model="form.projectDescribe" :rows="3" type="textarea" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="位置排序" prop="orderNumber">
            <el-input-number v-model="form.orderNumber" :min="1" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="填写备注">
            <el-input v-model="form.remark" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="info" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" border stripe highlight-current-row align="center" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column align="center" type="selection" width="55" />
        <el-table-column align="center" fixed="left" prop="projectName" label="项目名称" min-width="250" />
        <el-table-column align="center" prop="projectCode" label="项目编号" min-width="100" />
        <el-table-column align="center" prop="orderNumber" label="排序" min-width="80" />
        <el-table-column align="center" prop="createBy" label="创建者" min-width="100" />
        <el-table-column align="center" prop="updateBy" label="更新者" min-width="100" />
        <el-table-column align="center" prop="createTime" label="创建日期" min-width="170" />
        <el-table-column align="center" prop="updateTime" label="更新时间" min-width="170" />
        <el-table-column align="center" prop="remark" label="备注" min-width="250" />
        <el-table-column v-if="checkPer(['admin','project:edit','project:del'])" label="操作" min-width="200" align="center" fixed="right">
          <template slot-scope="scope">
            <udOperation :data="scope.row" :permission="permission" />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudProject from '@/api/workOrder/project'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = {
  projectName: null,
  projectCode: null,
  projectDescribe: null,
  orderNumber: null,
  remark: null
}
export default {
  name: 'Project',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: '项目',
      url: 'api/project',
      idField: 'projectId',
      sort: 'orderNumber,desc',
      crudMethod: { ...crudProject }
    })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'project:add'],
        edit: ['admin', 'project:edit'],
        del: ['admin', 'project:del']
      },
      rules: {
        projectName: [
          { required: true, message: '项目名称不能为空', trigger: 'blur' }
        ],
        projectCode: [
          { required: true, message: '项目编号不能为空', trigger: 'blur' }
        ],
        projectDescribe: [
          { required: true, message: '项目描述不能为空', trigger: 'blur' }
        ],
        orderNumber: [
          { required: true, message: '排序不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'projectName', display_name: '项目名称' },
        { key: 'projectCode', display_name: '项目编号' },
        { key: 'projectDescribe', display_name: '项目描述' },
        { key: 'orderNumber', display_name: '排序' },
        { key: 'createBy', display_name: '创建者' },
        { key: 'updateBy', display_name: '更新者' },
        { key: 'remark', display_name: '备注' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
